package com.jstyle.jclife.adapter;

import android.support.v7.widget.SwitchCompat;
import android.widget.CompoundButton;
import android.widget.TextView;

import com.jstyle.jclife.R;
import com.jstyle.jclife.daoManager.EnableDataDaoManager;
import com.jstyle.jclife.model.EnableData;

import java.util.List;

import butterknife.BindView;

/**
 * Created by Administrator on 2018/6/11.
 */

public class EnableAdapter extends RecyclerViewBaseAdapter<EnableData> {
    @BindView(R.id.tv_enable)
    TextView tvEnable;
    @BindView(R.id.SwitchCompat_item)
    SwitchCompat SwitchCompatItem;

    public EnableAdapter(List<EnableData> mDatas) {
        super(mDatas);
    }

    @Override
    protected void bindData(BaseViewHolder holder, int position) {
        final EnableData enableData=mDataList.get(position);
        String name=enableData.getDisplayName();
        boolean enable=enableData.getIsOn();
        SwitchCompatItem.setChecked(enable);
        SwitchCompatItem.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                enableData.setIsOn(isChecked);
                EnableDataDaoManager.insertEnableData(enableData);

            }
        });
        tvEnable.setText(name);
    }

    @Override
    protected int getLayoutId(int viewType) {
        return R.layout.item_enable;
    }
}
